home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / sc3x04.exe / SEMAINFO.C < prev    next >
Text File  |  1992-10-08  |  5KB  |  129 lines

  1. //   ╔════════════════════════════════════════════════════════════════════╗
  2. //   ║                                                                    ║
  3. //   ║ module:      semainfo.c                                            ║
  4. //   ║ abstract:    This module shows how to make the GetSemaphoreIn-     ║
  5. //   ║              formation system call using the F2 Shell Interface.   ║
  6. //   ║              Obviously, it requires the NetWare Shell.             ║
  7. //   ║                                                                    ║
  8. //   ║              This call may need to be made iteratively to return   ║
  9. //   ║              all of the semaphore information.  For simplicity,    ║
  10. //   ║              this example only makes the call once.                ║
  11. //   ║                                                                    ║
  12. //   ║ environment: NetWare 3.x v3.11                                     ║
  13. //   ║              Borland C 3.0                                         ║
  14. //   ║                                                                    ║
  15. //   ║  This software is provided as is and carries no warranty           ║
  16. //   ║  whatsoever.  Novell disclaims and excludes any and all implied    ║
  17. //   ║  warranties of merchantability, title and fitness for a particular ║
  18. //   ║  purpose.  Novell does not warrant that the software will satisfy  ║
  19. //   ║  your requirements or that the software is without defect or error ║
  20. //   ║  or that operation of the software will be uninterrupted.  You are ║
  21. //   ║  using the software at your risk.  The software is not a product   ║
  22. //   ║  of Novell, Inc. or any of subsidiaries.                           ║
  23. //   ╚════════════════════════════════════════════════════════════════════╝
  24. //                         ****** N O T I C E ******
  25. //    
  26. //     This software is considered pre-release and may be used at your own
  27. //     risk and has been provided due to the many requests of our cust-
  28. //     omers. 
  29. //
  30.  
  31. #include <stdio.h>
  32. #include <string.h>
  33. #include <stdlib.h>
  34. #include <conio.h>
  35.  
  36. #include "nwsys.h"
  37.  
  38. //
  39. //  First of all, we define the request and reply structures which are
  40. //  needed for the GetSemaphoreInformation API call.  These structures are
  41. //  layed out according to the System Call documentation.
  42. //
  43.  
  44. struct  {
  45.     WORD    sflen;          // length of the structure
  46.     BYTE    sfcode;         // the subfunction code
  47.     WORD    lastRecordSeen; // sequence
  48.     BYTE    semaphoreNameLength;
  49.                             // length of the semaphore name
  50.     char    semaphoreName[128];
  51.                            // semaphore name
  52. }Request;
  53.  
  54. struct connStruct {
  55.     WORD    connectionNumber;
  56.                             // Connection holding semaphore open
  57.     WORD    taskNumber;     // task number holding semaphore open
  58. };
  59.  
  60. struct  {
  61.     WORD    nextRequestRec; // next record to be requested, sequence
  62.     WORD    openCount;      // total number of times opened
  63.     WORD    value;          // value of semaphore
  64.     BYTE    semaphoreCount; //  number of semaphores in this iteration
  65.     struct  connStruct conn[125];
  66.                             //  Array of connection information
  67. } Reply;
  68.  
  69. int numConnections;
  70. char semaphoreName[128];
  71.  
  72. void processEntries(void);
  73. void displayData(void);
  74. //
  75. //  This routine calculates the number of connections.
  76. //
  77. void ProcessEntries(void)
  78. {
  79.     numConnections+=Reply.semaphoreCount;
  80. }
  81.  
  82. //
  83. //  Display the SemaphoreInformation.
  84. //
  85. void DisplayData( void )
  86. {
  87.     int i;
  88.  
  89.     clrscr();
  90.     printf("\n\nSemaphore Information For %s  Value: %d\n\n",
  91.                 semaphoreName,Reply.value);
  92.     printf("Conn   Task\n");
  93.     printf("----   ----\n");
  94.     for(i=0;i<numConnections;i++) {
  95.         printf(" %02d ",WordSwap(Reply.conn[i].connectionNumber));
  96.         printf("    %02d\n",WordSwap(Reply.conn[i].taskNumber));
  97.     }
  98. }
  99. //
  100. //  This is the main program.  The purpose is to make the GetSemaphore
  101. //  Information API call to illustrate making system calls using the F2
  102. //  interface.
  103. //
  104.  
  105. void main(int argc, char *argv[])
  106. {
  107.     int     cc;
  108.     int     length;
  109.  
  110.     if(argc!=2){printf("usage: SEMAINFO semaphoreName\n");exit(1);}
  111.     strcpy(semaphoreName,argv[1]);
  112.     numConnections=0;
  113. //
  114. //  Build the request buffer
  115. //
  116.     Request.sflen = strlen(semaphoreName) + 6;
  117.     Request.sfcode = 242;                       // subfunction code
  118.     length=strlen(semaphoreName);
  119.     Request.semaphoreNameLength=(BYTE)length;
  120.     memcpy(Request.semaphoreName,semaphoreName,strlen(semaphoreName));
  121.     Request.lastRecordSeen = 0;
  122.     cc = NWSystemCall(23,&Request,sizeof Request,&Reply,sizeof Reply);
  123.     printf("Function returned:    %03d--%#02x\n",cc,cc);
  124.     if( cc == 0 ) {
  125.         ProcessEntries();
  126.         DisplayData();
  127.     }
  128. }
  129.